package com.gather.treesets;

import java.util.Comparator;
import java.util.TreeSet;

public class Example04 {
    public static void main(String[] args) {
        System.out.println("比较字符串的长度大小");
        TreeSet<String> strings = new TreeSet<>(new Comparator<String>() {
            @Override
            public int compare(String o1, String o2) {
                int l = o1.length() - o2.length();
                // 长度一样是，比较字母排序
                int n =o1.compareTo(o2);
                return (l == 0) ? n : l;
            }
        });
        strings.add("xiao");
        strings.add("a");
        strings.add("length");
        strings.add("ha");
        strings.add("abcdefghijkl");
        System.out.println(strings.toString());
    }
}
